package com.example.administrator.easy.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.administrator.easy.R;
import com.example.administrator.easy.model.GuangFlResult;

import org.xutils.image.ImageOptions;
import org.xutils.x;

import java.util.ArrayList;

/**
 * Created by Administrator on 2016/11/14.
 */

public class GuangFlAdapter extends BaseAdapter {//
    private Context mContext;
    private ArrayList<GuangFlResult> mList;
    private ImageOptions options;
    public  GuangFlAdapter(Context context,ArrayList<GuangFlResult> list){
        mContext = context;
        mList = list;
        options = new ImageOptions.Builder().setUseMemCache(true).setRadius(10).build();

    }
    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder vh;
        if(convertView==null){
            convertView = View.inflate(mContext,R.layout.fragment_guang_fl_item,null);
            vh = new ViewHolder(convertView);
            convertView.setTag(vh);
        }else{
            vh = (ViewHolder) convertView.getTag();
        }

        x.image().bind(vh.iv,mList.get(position).getIco(),options);
////        //此处需要判断时间来决定显示红的还是灰的
//        String sEnd = mList.get(position).getEventsEnd();
//        String jie = sEnd.substring(6,18);
//        long end = Long.parseLong(jie);//截止时间
//        long now = System.currentTimeMillis();//现在时间
//        if(end-now<=0){//已经结束
//            vh.tvhong.setVisibility(View.INVISIBLE);
//            vh.tvhui.setVisibility(View.VISIBLE);
//
//        }else{//剩余
//            vh.tvhong.setVisibility(View.VISIBLE);
//            vh.tvhui.setVisibility(View.INVISIBLE);
//            long z = end-now;
//            int hour = (int) (z/60*60*1000);
//            if(hour/24>1){
//                vh.tvhong.setText("剩余"+hour/24+"天");
//            }else{
//                vh.tv2.setText("不到1天");
//            }
//
//        }

        vh.tv.setText(mList.get(position).getTitle());//活动标题
        return convertView;
    }
    class ViewHolder{
        ImageView iv;
        TextView tv,tv2,tvhong,tvhui;
        public ViewHolder(View view){
            iv = (ImageView) view.findViewById(R.id.ivv);
            tv = (TextView) view.findViewById(R.id.tvbiao);
            tvhong = (TextView) view.findViewById(R.id.hong);
            tvhui = (TextView) view.findViewById(R.id.hui);
        }
    }
}
